#include <stdio.h>
#include <stdlib.h>

/* 用递归求n! */

int fun(int n)
{
    int sum;
    if (n < 0)
    {
        printf("请输入大于0的整数");
    }
    else if (n == 1 || n == 0)
    {
        sum = 1;
    }
    else
    {
        sum = fun(n - 1) * n;
    }
    return sum;
}

int main()
{
    int n;
    printf("请输入一个整数:");
    scanf("%d", &n);
    printf("%d阶乘的结果为:%d\n", n, fun(n));
    system("pause");
    return 0;
}